import Vue from "vue";
import Router from "vue-router";

const Login = () => import("~/view/login").then(m => m.default || m);
const Index = () => import("~/view/index").then(m => m.default || m);
const Help = () => import("~/view/help").then(m => m.default || m);
const publicQuery = import("~/view/publicQuery").then(m => m.default || m);

import Test from "./modules/test";
import BasicModule from "./modules/BasicModule";
import StudentFilesModule from "./modules/StudentFilesModule"; //学生管理
import Teacher from "./modules/Teacher"; //教职工管理
import TeacherStaffAre from "./modules/TeacherStaffAre"; //教职工考勤管理
import Documents from "./modules/Documents"; //公文流转
import Leave from "./modules/Leave"; //请假管理
import DutyModule from "./modules/DutyModule"; //值班
import SystemIndex from "./System/index"; //系统管理
Vue.use(Router);

/**
 * hidden: true                  如果设置为true，项目将不会显示在侧栏中(默认为false)
 *
 * redirect: noRedirect          如果设置noRedirect，则不会在面包屑中重定向
 * name:'router-name'            名称由<keep-alive>(必须设置!!)使用
 * meta : {
    title: 'title'               名称显示在侧边栏和面包屑(推荐集)
    icon: 'svg-name'             图标显示在侧栏中
  }
 */
export const constantRoutes = [
  {
    path: "/",
    name: "index",
    hidden: true,
    component: Index
  },
  {
    path: "/login",
    hidden: true,
    component: Login
  },
  ...Test
];
export const asyncRoutes = [
  {
    path: "/publicQuery",
    component: publicQuery,
    name: "publicQuery",
    authentication: "publicQuery"
  },
  {
    path: "/help",
    component: Help,
    redirect: "/help",
    name: "help",
    authentication: "help"
  },
  ...SystemIndex,
  ...BasicModule,
  ...StudentFilesModule,
  ...Teacher,
  ...TeacherStaffAre,
  ...Documents,
  ...Leave,
  ...DutyModule,
  // 404 page must be placed at the end !!!
  { path: "*", redirect: "/404", hidden: true }
];

const router = new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
});

export function resetRouter() {
  const newRouter = router();
  router.matcher = newRouter.matcher; // reset router
}

export function createRouter() {
  return router;
}
